<template>
  <a-table :columns="columns" :data-source="tabledata" @change="onPagination" :pagination="pagination">
    <template #timestamp="{ text }">
      <div>
        {{FormatTime(text)}}
      </div>
    </template>
  </a-table>
</template>
<script lang='ts'>
import { reactive, toRefs } from "vue";
import { dowrecord } from "@/api/mergeApi/index";
import { FormatTime } from "@/CommonAssets/index";
export default {
  name: "下载记录",
  props: {
    drawerdata: Object,
  },
  setup(props: any) {
    const data = reactive({
      tabledata: [],
      columns: [
        {
          title: "下载时间",
          dataIndex: "timestamp",
          align: "center",
          slots: { customRender: "timestamp" },
        },
        {
          title: "下载城市",
          dataIndex: "local",
          ellipsis: true,
          align: "center",
        },
        {
          title: "下载IP",
          dataIndex: "ip",
          ellipsis: true,
          align: "center",
        },
        {
          title: "重复下载",
          dataIndex: "repeat",
          ellipsis: true,
          align: "center",
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        hideOnSinglePage: true,
        current: 1,
      },
    });
    if (props.drawerdata.apptype == "superModel") {
      data.columns.push({
        title: "用户UDID",
        dataIndex: "udid",
        ellipsis: true,
        align: "center",
      });
    }
    async function record(pageNo = 1) {
      const reslut = await dowrecord({
        lid: props.drawerdata.lid,
        pageNo,
        pageSize: 10,
      });
      reslut.data.data.forEach((element: any) => {
        element.key = element._id;
      });
      data.pagination.total = reslut.data.total;
      data.tabledata = reslut.data.data;
    }
    record();

    function onPagination(value: {
      current: number;
      pageSize: number;
      total: number;
    }) {
      data.pagination.current = value.current;
      record(value.current);
    }

    return {
      ...toRefs(data),
      onPagination,
      FormatTime,
    };
  },
};
</script>